﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebService_Newstore.DAO
{
    public class HyperDAO:BaseDAO
    {
        public int id;
        public string nom;
        public string rue;
        public string cplAdresse;
        public string cPostal;
        public string ville;
        public int idPays;
        public int telephone;
        public string eMail;

        //constructeur pour chargement par l'ID
        public HyperDAO(int idHyper)
        {
            using (newStoreContext = new newStoreEntities())
            {
                try
                {
                    var userQuery = from hyper in newStoreContext.hypers
                                    where hyper.id_hyper == idHyper
                                    select hyper;

                    if (userQuery.LongCount() == 0)
                    {
                        //On instancie un DAO vide pour faire remonter l'erreur au niveau du controller
                        this.id = 0;
                    }

                    foreach (var ligne in userQuery)
                    {
                        //On instancie le BP
                        this.id = ligne.id_hyper;
                        this.nom = ligne.nom_hyper;
                        this.rue = ligne.rue_hyper;
                        this.cplAdresse = ligne.adrCpl_hyper;
                        this.cPostal = ligne.CPostal_hyper;
                        this.ville = ligne.ville_hyper;
                        this.idPays = (int)ligne.id_pays_hyper;
                        this.telephone = (int)ligne.tel_hyper;
                        this.eMail = ligne.mail_hyper;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.ReadLine();
                }
            }
        }
    }
}